/**
 * Created by root on 17-8-6.
 */
var app = require('../../app');
var logger = require('../../config/log4js');

module.exports = {

    queryReptile(size, callback) {
        return new Promise(function (resolve, reject) {
            try {

                //获取数据源
                var dbPool = app.getDB();

                dbPool.getConnection(function(err, connection) {
                    if (err) throw err;
                    // Use the connection
                    connection.query('SELECT * FROM ip_list ORDER BY create_date DESC LIMIT 0,?', [size], function (error, results, fields) {
                        // And done with the connection.
                        connection.release();

                        // Handle error after the release.
                        if (error) throw error;

                        // Don't use the connection here, it has been returned to the pool.
                        logger.access.info(results);
                        callback(results);

                        resolve(results);
                    });
                });

            } catch (e) {
                logger.error.info(e);
                reject(e.toString());
            }
        });
    }

}
